package org.meb.conquest.rest.json;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.meb.conquest.db.model.Deck;
import org.meb.conquest.rest.auth.AuthUser;
import org.meb.conquest.rest.json.model.JsonDeck;
import org.meb.conquest.rest.service.DeckService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DeckLoader {

	private static final Logger log = LoggerFactory.getLogger(DeckLoader.class);

	@Inject
	private DeckService deckService;

	@Inject
	private AuthUser authUser;

	public List<JsonDeck> loadDecks() {
		log.info("loadDecks(): auth user: {}", authUser);

		List<Deck> decks = deckService.findUserDecks();
		List<JsonDeck> jsonCards = new ArrayList<>();
		for (Deck deck : decks) {
			jsonCards.add(new JsonDeck(deck));
		}
		return jsonCards;
	}

	public JsonDeck loadDeck(Long id, Boolean includeMembers) {
		log.info("loadDeck(): auth user: {}", authUser);

		Deck deck = deckService.findUserDeck(id);
		if (deck == null) {
			return null;
		} else {
			return new JsonDeck(deck, includeMembers);
		}
	}
}
